<template>
  <Dialog v-model="dialogVisible" :appendToBody="true" title="邀请记录" width="70%">
    <!-- 搜索工作栏 -->
    <!--<el-form
      ref="queryFormRef"
      :inline="true"
      :model="queryParams"
      class="-mb-15px"
      label-width="82px"
    >
      <el-form-item label="激活码" prop="name">
        <el-input
          v-model="queryParams.activationCode"
          class="!w-240px"
          placeholder="请输入激活码"
          clearable
          @keyup="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button @click="handleQuery">
          <Icon class="mr-5px" icon="ep:search" />
          搜索
        </el-button>
      </el-form-item>
    </el-form>-->

    <!-- 列表 -->
    <el-table v-loading="loading" :data="list" show-overflow-tooltip>
      <el-table-column label="主键id" align="center" prop="id" v-if="false"/>

      <el-table-column label="邀请人昵称" align="center" prop="inviterNickname" />
      <el-table-column label="邀请人Id" align="center" prop="inviteeUserId" />
      <el-table-column label="被邀请人昵称" align="center" prop="inviteeNickname" />
      <el-table-column align="center" label="充值状态" prop="rechargeStatus" width="100px">
        <template #default="scope">
          <dict-tag :type="DICT_TYPE.RECHARG_STATUS" :value="scope.row.rechargeStatus" />
        </template>
      </el-table-column>
      <el-table-column
        label="注册时间"
        align="center"
        prop="createTime"
        :formatter="dateFormatter"
        width="180px"
      />
    </el-table>
    <!-- 分页 -->
    <Pagination
      v-model:limit="queryParams.pageSize"
      v-model:page="queryParams.pageNo"
      :total="total"
      @pagination="getList"
    />
    <div class="clear-both"></div>
  </Dialog>
</template>
<script lang="ts" setup>
  import { DICT_TYPE } from '@/utils/dict'
  import { dateFormatter } from '@/utils/formatTime'
  import * as WrittenApi from '@/api/member/written'
  defineOptions({ name: 'UserOrderList' })
  const message = useMessage() // 消息弹窗
  const total = ref(0) // 列表的总页数
  const list = ref<any[]>([]) // 列表的数据
  const loading = ref(false) // 列表的加载中
  const dialogVisible = ref(false) // 弹窗的是否展示
  const queryParams = ref({
    pageNo: 1,
    pageSize: 10,
    userId: null
  }) // 查询参数
  const queryFormRef = ref() // 搜索的表单
  /** 打开弹窗 */
  const open = (ids: number[]) => {
    queryParams.value.userId = ids
    // 打开时重置查询，防止发送列表剩余数量未更新的问题
    resetQuery()

    dialogVisible.value = true
  }
  defineExpose({ open }) // 提供 open 方法，用于打开弹窗

  /** 查询列表 */
  const getList = async () => {
    loading.value = true
    try {
      const data = await WrittenApi.getMemberPromotionPage(queryParams.value)
      list.value = data.list
      total.value = data.total
    } finally {
      loading.value = false
    }
  }

  /** 搜索按钮操作 */
  const handleQuery = () => {
    queryParams.value.pageNo = 1
    getList()
  }

  /** 重置按钮操作 */
  const resetQuery = () => {
    queryFormRef?.value?.resetFields()
    handleQuery()
  }
</script>
